package org.millioncall.yueyoga.admin.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.millioncall.yueyoga.admin.dao.TumTaskDAO;
import org.millioncall.yueyoga.admin.model.TumTask;
import org.millioncall.yueyoga.admin.service.TumTaskService;
import org.springframework.stereotype.Service;

@Service
public class TumTaskServiceImpl implements TumTaskService {

	private TumTaskDAO tumTaskDAO;
	private Map<String, Object> map = new HashMap<String, Object>();;

	@Override
	public boolean save(TumTask tumTask) {
		if (tumTask != null) {
			if (tumTask.getTaskId() != null) {
				map.put("taskId", tumTask.getTaskId());
			}
			if (tumTask.getMemberId() != null) {
				map.put("memberId", tumTask.getMemberId());
			}
			if (StringUtils.isNotBlank(tumTask.getUserId())) {
				map.put("userId", tumTask.getUserId());
			}
			return tumTaskDAO.save(map) > 0 ? true : false;
		}
		return false;
	}

	@Override
	public boolean update(TumTask tumTask) {
		if (tumTask != null) {
			if (StringUtils.isNotBlank(tumTask.getUserId())) {
				map.put("userId", tumTask.getUserId());
			}
			map.put("tumId", tumTask.getTumId());
			return tumTaskDAO.update(map) > 0 ? true : false;
		}
		return false;
	}

	@Override
	public boolean deleteById(Integer id) {
		return tumTaskDAO.deleteById(id) > 0 ? true : false;
	}

	@Override
	public boolean deleteByIds(String[] ids) {
		return tumTaskDAO.deleteByIds(ids) > 1 ? true : false;
	}

	public TumTaskDAO getTumTaskDAO() {
		return tumTaskDAO;
	}

	public void setTumTaskDAO(TumTaskDAO tumTaskDAO) {
		this.tumTaskDAO = tumTaskDAO;
	}

}
